using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GUIManager : MonoBehaviour
{
	public static GUIManager Instance;

	public GameObject panelUIGPL;

	public Text txtCountdown;

	public PlayerControlManager ControlManager;

	public GameObject goBtnEject;

	public GameObject rateUsPannel;

	public Text txtCoinmain;

	public VehicleSelectManager vehicleSelect;

	public MissionControl missionControl;

	public ScoreEndGame scoreEndGame;

	public Text textStatus;

	public GameObject statusVehicle;

	public bool modeTest;

	public FireworkScript fireWork;

	private IEnumerator delayCheckUpdateStatusVehicle()
	{
		yield return new WaitForSecondsRealtime(1f);
		UpdateStatusVehicle();
	}

	public void UpdateStatusVehicle()
	{
		int num = vehicleSelect.CheckStatus();
		if (num > 0)
		{
			statusVehicle.SetActive(value: true);
			textStatus.text = string.Concat(num);
		}
		else
		{
			statusVehicle.SetActive(value: false);
		}
	}

	public void SetOrtSize(float size)
	{
	}

	private void Awake()
	{
		CoinManager.GetCoin();
		UpdateTextCoin();
		BadLogic.playing = false;
		BadLogic.pause = false;
		SetOrtSize(10f);
	}

	private void Start()
	{
		Instance = this;
		_PanelUIGPLStatus(status: true);
		disable_txtCountdown();
		hideButtonEject();
		missionControl.showMission();
		scoreEndGame.gameObject.SetActive(value: false);
		StartCoroutine(delayCheckUpdateStatusVehicle());
	}

	public void _PanelUIGPLStatus(bool status)
	{
		panelUIGPL.SetActive(status);
	}

	public void _Countdown(string text)
	{
		if (!txtCountdown.enabled)
		{
			txtCountdown.enabled = true;
		}
		txtCountdown.text = (text ?? "");
	}

	public void disable_txtCountdown()
	{
		if (txtCountdown.enabled)
		{
			txtCountdown.enabled = false;
		}
	}

	public void _reset()
	{
		ControlManager.click_Reset();
	}

	public void showButtonEject()
	{
		goBtnEject.SetActive(value: true);
	}

	public void hideButtonEject()
	{
		goBtnEject.SetActive(value: false);
	}

	public void UpdateTextCoin()
	{
		txtCoinmain.text = string.Concat(CoinManager.coin);
	}

	public void OnClick_Vehicle()
	{
		vehicleSelect.ShowVehicleSelect();
        if (!AdManager1.instance.ShieldAddress) AdManager.single.ShowNative();
    }

	public void HideSelectVehicle()
	{
		vehicleSelect.HideVehicleSelect();
		UpdateStatusVehicle();
	}

	public void ClickAgain()
	{
		PlayerControlManager.Instance.click_Reset();
		missionControl.resetsaukhiHoanthanh();
		missionControl.showMission();
		Object.FindObjectOfType<ScoreEndGame>().HideAnimation();
		Time.timeScale = 1f;
		BadLogic.pause = false;
		fireWork.resetGO();
		Object.FindObjectOfType<ScoreEndGame>().ResetDoubleCoinText();
        //AdManager.Instance.ShowInterstitial();
        if (!AdManager1.instance.ShieldAddress) AdManager.single.ShowNative();
    }

	public void ClickToMenu()
	{
		SceneManager.LoadScene("Home");
        //AdManager.Instance.ShowInterstitial();
        if (!AdManager1.instance.ShieldAddress) AdManager.single.ShowNative();
    }

	public void showEndGame()
	{
		scoreEndGame.SHOW();
	}

	private void Update()
	{
		if (UnityEngine.Input.GetKeyDown(KeyCode.E))
		{
			showEndGame();
			missionControl.ShowMissioEndgame();
		}
	}

	public void GoRateUs()
	{
		PlayerPrefs.SetInt("has_rateus", 1);
		rateUsPannel.SetActive(value: false);
		FirebaseStat.Instance.LogSimpleEvent("ns_rate_us_ok");
		Application.OpenURL("market://details?id=" + Application.identifier);
	}

	public void OnCloseRateUs()
	{
		rateUsPannel.SetActive(value: false);
		FirebaseStat.Instance.LogSimpleEvent("ns_rate_us_cancel");
	}

	public void ShowRateUsOrAd()
	{
		//if (PlayerPrefs.GetInt("has_rateus", 0) == 1)
		//{
		//	AdManager.Instance.ShowInterstitial();
		//}
		//else if (UnityEngine.Random.Range(0, 100) < 33)
		//{
		//	rateUsPannel.SetActive(value: true);
		//}
		//else
		//{
		//	AdManager.Instance.ShowInterstitial();
		//}
	}

	public void OnEndGame()
	{
		BadLogic.pause = true;
		//Time.timeScale = 0f;
		showEndGame();
		missionControl.ShowMissioEndgame();
		fireWork._Play();
		ControlManager._OnEndGame();
		//FirebaseStat.Instance.LogFinishLevel(BadLogic.nameMap, VehiclesManager.Instance.indexVehicles + 1, ScoreManager.Instance.coinEarned);
		//if ((DataManager.Instance.IntAds >= 1) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQAQ", 100.0, delegate
		//	{
		//	});
		//}
		//if ((DataManager.Instance.Missions >= 1) & (DataManager.Instance.Missions < 3) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQAg", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((DataManager.Instance.Missions >= 3) & (DataManager.Instance.Missions < 5) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQAw", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((DataManager.Instance.Missions >= 10) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQBA", 100.0, delegate
		//	{
		//	});
		//}
		//if ((DataManager.Instance.Maps >= 5) & (DataManager.Instance.Maps < 10) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQBQ", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((DataManager.Instance.Maps >= 10) & (DataManager.Instance.Maps < 15) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQBg", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((DataManager.Instance.Maps >= 15) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQBw", 100.0, delegate
		//	{
		//	});
		//}
		//if ((DataManager.Instance.Vehicle >= 5) & (DataManager.Instance.Vehicle < 7) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQCA", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((DataManager.Instance.Vehicle >= 7) & (DataManager.Instance.Vehicle < 11) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQCQ", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((DataManager.Instance.Vehicle >= 11) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQCg", 100.0, delegate
		//	{
		//	});
		//}
		//if ((DataManager.Instance.X2Coins >= 10) & (DataManager.Instance.X2Coins < 20) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQCw", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((DataManager.Instance.X2Coins >= 20) & (DataManager.Instance.X2Coins < 50) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQDA", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((DataManager.Instance.X2Coins >= 50) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQDQ", 100.0, delegate
		//	{
		//	});
		//}
		//if ((PlayerPrefs.GetInt(BadLogic.nameMap + "BESTSCORE") >= 10000) & (PlayerPrefs.GetInt(BadLogic.nameMap + "BESTSCORE") < 100000) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQDg", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((PlayerPrefs.GetInt(BadLogic.nameMap + "BESTSCORE") >= 100000) & (PlayerPrefs.GetInt(BadLogic.nameMap + "BESTSCORE") < 1000000) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQDw", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((PlayerPrefs.GetInt(BadLogic.nameMap + "BESTSCORE") >= 1000000) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQEA", 100.0, delegate
		//	{
		//	});
		//}
		//if ((PlayerPrefs.GetInt("COIN") >= 5000) & (PlayerPrefs.GetInt("COIN") < 50000) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQEQ", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((PlayerPrefs.GetInt("COIN") >= 50000) & (PlayerPrefs.GetInt("COIN") < 250000) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQEg", 100.0, delegate
		//	{
		//	});
		//}
		//else if ((PlayerPrefs.GetInt("COIN") >= 250000) & (LeaderboardController.checkSignIn == 1))
		//{
		//	Social.ReportProgress("CgkIneXCn60GEAIQEw", 100.0, delegate
		//	{
		//	});
		//}
	}

	public void showPause()
	{
		BadLogic.pause = true;
		Time.timeScale = 0f;
        //if (!AdManager1.instance.ShieldAddress) AdManager.single.ShowNative();
    }

	public void hidePause()
	{
		Time.timeScale = 1f;
		BadLogic.pause = false;
        //if (!AdManager1.instance.ShieldAddress) AdManager.single.ShowNative();
    }
}
